package com.studentstreet.tools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.widget.TextView;

public class RexPattern {
	public static void setText(TextView tv, String key) {
		SpannableString s = new SpannableString(tv.getText());
		Pattern p = null;
		if ("".equals(key)) {
			p = Pattern.compile("empty");
		} else {
			p = Pattern.compile(key);
		}
		Matcher m = p.matcher(s);
		while (m.find()) {
			int start = m.start();
			int end = m.end();
			s.setSpan(new UnderlineSpan(), start, end,
					Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			s.setSpan(new ForegroundColorSpan(Color.BLUE), start, end,
					Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		}
		tv.setText(s);

	}
}
